package com.zbec.mdrs.service;

import com.zbec.framework.core.service.SystemDictionaryService;
import com.zbec.framework.core.util.PageUtils;
import com.zbec.framework.core.vo.JqgridResponse;
import com.zbec.framework.core.vo.PageInfo;
import com.zbec.mdrs.constants.Constants;
import com.zbec.mdrs.repository.jpa.ReportTaskDao;
import com.zbec.mdrs.vo.ReportTaskVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by fxl on 2015/11/10.
 */
@Component
@Transactional
public class ReportTaskService {
    @Autowired
    private ReportTaskDao reportTaskDao;

    @Autowired
    private SystemDictionaryService systemDictionaryService;

    public JqgridResponse<ReportTaskVo> findAllTask(PageInfo pageInfo) {

        Page<ReportTaskVo> taskVoPage= reportTaskDao.findAllTask(PageUtils.buildPageRequest(pageInfo));
        packagingBean(taskVoPage.getContent());
        return PageUtils.buildResponse(taskVoPage, taskVoPage.getContent());
    }

    public void  packagingBean(List<ReportTaskVo> list){
        for (int i = 0; i <list.size() ; i++) {
            ReportTaskVo taskVo=list.get(i);
            taskVo.setBusinessTypeDesc(systemDictionaryService.getSystemDictionaryDesc(Constants.Constants_YWLX, taskVo.getBusinessType()));
            taskVo.setStatusDesc(systemDictionaryService.getSystemDictionaryDesc(Constants.Constants_SBZT, taskVo.getStatus()));
        }
    }
}
